package com.corner.model.cornerservice.service;

import com.corner.app.GlobalParams;
import com.corner.model.cornerservice.utils.DigestUtil;
import com.google.gson.GsonBuilder;

import java.security.NoSuchAlgorithmException;

import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.RestAdapter.LogLevel;
import retrofit.converter.GsonConverter;

public class Service {

    public static final String OBJECT_ID = "objectId";
    public static String COUNT = "count";
    private static Service instance = new Service();
//    	private String api = "http://192.168.1.103:8080/CornerService";
    private String api = "http://hellocityweb.cn:8080/CornerService";
    private RestAdapter adapter = new RestAdapter.Builder().setEndpoint(api).
            setConverter(new GsonConverter(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()))
            .setRequestInterceptor(new RequestInterceptor() {
                @Override
                public void intercept(RequestFacade requestFacade) {
                    try {
                        requestFacade.addHeader("Authorization", DigestUtil.getDigest(GlobalParams.deviceId));
                    } catch (NoSuchAlgorithmException e) {
                        e.printStackTrace();
                    }
                }
            })
            .setLogLevel(LogLevel.FULL).setErrorHandler(new MyErrorHandler())
            .build();
    public UserService userService = adapter.create(UserService.class);

    public InfoService infoService = adapter.create(InfoService.class);
    public LocationService locationService = adapter
            .create(LocationService.class);
    public ConversationService conversationService = adapter
            .create(ConversationService.class);
    public LikeService likeService = adapter.create(LikeService.class);
    public ReportUserService reportUserService = adapter
            .create(ReportUserService.class);
    public ReportInfoService reportInfoService = adapter
            .create(ReportInfoService.class);
    public AttentionService attentionService = adapter
            .create(AttentionService.class);
    public TokenService tokenService = adapter
            .create(TokenService.class);
    public UpdateService updateService = adapter
            .create(UpdateService.class);
    public CQLService cqlService = adapter
            .create(CQLService.class);
    private Service() {
    }

    public static Service getInstance() {
        return instance;
    }

}
